package com.onlyphoto.onlymall.mvp.view.binder

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

import com.onlyphoto.onlymall.R
import com.onlyphoto.onlymall.bean.response.GoodsBean
import com.onlyphoto.onlymall.mvp.view.activity.GoodsDetailsActivity

import me.drakeet.multitype.ItemViewBinder

/**
 * Created by gaochujia on 2019-07-09.
 */
class SearchBinder : ItemViewBinder<GoodsBean, SearchBinder.ViewHolder>() {

    override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {
        val root = inflater.inflate(R.layout.item_search, parent, false)
        return ViewHolder(root)
    }

    override fun onBindViewHolder(viewHolder: ViewHolder, bean: GoodsBean) {
        viewHolder.update(bean)
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        var name: TextView? = null

        init {
            name = itemView.findViewById(R.id.name)

        }

        fun update(bean: GoodsBean) {
            name?.text = bean.title

            itemView.setOnClickListener{
                itemView.context.startActivity(Intent(itemView.context, GoodsDetailsActivity::class.java)
                        .putExtra("goodsId", bean.id))
            }
        }
    }
}
